home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11164 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.3 KB  |  107 lines

  1. Path: unixg.ubc.ca!news
  2. From: gordonw@unixg.ubc.ca (Gordon Wong)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP. How to convert '0x12' into FF char?
  5. Date: Fri, 22 Mar 1996 06:59:05 GMT
  6. Organization: The University of British Columbia
  7. Message-ID: <4itj1h$p8e@nntp.ucs.ubc.ca>
  8. References: <4iissm$s76@nntp.ucs.ubc.ca> <4il52a$ma7@nntp.interaccess.com>
  9. NNTP-Posting-Host: port20.annex2.net.ubc.ca
  10. X-Newsreader: Forte Free Agent 1.0.81
  11.  
  12. Thanks to all for the responses.  Here's the program (it now works for
  13. the most part) I am wrote to take a Mozilla response from a HTML form
  14. and get rid of the %0A%0D (CRLF) and %28(left paren) embedded codes
  15. (for example) in the reply string that gets emailed back to me.  There
  16. is a program in some archive somewhere that does this but I could not
  17. find it.
  18.  
  19. Example input: 
  20. Name=Jason+Sutton&Address=221+Patino+Way+S.W.&City=Calamzoo&State=AB&Zip=T2V+5J6&Phone1=%28453%29251-1213&Phone2=%28453%29435-7698&Fax=&Full=on&Part=on&Classical=on&StartWhen=in+a+few+months&Comments=I+am+currently+a+student+at+the+University+of+Alberta%0D%0A+and+would+like+to+start+studies+in+animation+as+soon+as+possible....%0D%0AI+have+currently+taken+an+introductory+art+course+at+the+universtity%0D%0Alevel+and+would+like+information+on+possible+summer+courses....%0D%0A%0D%0A
  21.  
  22. Becomes:
  23. Name=Jason Sutton
  24. Address=221 Patino Way S.W.
  25. City=Calamzoo
  26. State=AB
  27. Zip=T2V 5J6
  28. Phone1=(453)251-1213
  29. Phone2=(453)435-7698
  30. Fax=
  31. Full=on
  32. Part=on
  33. Classical=on
  34. StartWhen=in a few months
  35. Comments=I am currently a student at the University of Alberta
  36.  and would like to start studies in animation as soon as possible.
  37. I have currently taken an introductory art course at the universtity
  38. level and would like information on possible summer courses.
  39.  
  40. And here's the code (excuse the awkwardnesses):
  41. /*   Fix email from Mozilla forms.  Uses stream I/O.
  42.      1. Change all "+" to " "
  43.      2. Change all "&" to newlines
  44.      3. Change all "%**" to ASCII chars (where ** is 2 hex chars)
  45.  
  46.      Use:  Filtmoz  infile  outfile
  47.                                              gw/vima  Mar'96  */
  48. #include <stdio.h>
  49.     FILE *infile;
  50.     FILE *outfile;
  51.  
  52. int init_files(char *pars[])
  53. {
  54.    if ( ( infile = fopen(pars[1],"r")) == NULL ||
  55.         (outfile = fopen(pars[2],"w")) == NULL )  {
  56.         puts("\nCan't open file(s)\n");
  57.         return(0);
  58.    }
  59.    return(1);
  60. };
  61.  
  62. void filtmoz() {
  63.  
  64.   char c,d,e,s[5];
  65.   c=fgetc(infile);
  66.  
  67.   while (c != EOF)  {   /* scan file byte by byte */
  68.  
  69.     switch (c) {
  70.         case '+' : c = ' '; fputc(c,outfile); break;
  71.         case '&' : fputc('\n',outfile); break;
  72.         case '%' : /* Any % encountered signals an ASCII Char */
  73.                    {
  74.                       d=fgetc(infile);
  75.                       e=fgetc(infile);
  76.                       sprintf(s, "0x%c%c", d, e);
  77.                       sscanf(s,"%x",&c);
  78.                       /*fprintf("is '%c'.",c);*/
  79.                       fputc(c,outfile);
  80.                       break;
  81.                    }
  82.         default  : fputc(c,outfile); break;
  83.     }
  84.     c=fgetc(infile);
  85.   }
  86. }
  87.  
  88. main(int argc,char *argv[])
  89. {
  90.   char *doc1, *doc2;
  91.   doc1="\n FILTMOZ - cleans up email from Mozilla forms processing.";
  92.   doc2="\n       Usage:  FILTMOZ infile outfile \n";
  93.  
  94.   if (argc == 3) {
  95.      if (init_files(argv))  filtmoz();
  96.   }
  97.   else {
  98.      puts(doc1);
  99.      puts(doc2);
  100.   }
  101. }
  102.  
  103. Gordon Wong, gordonw@unixg.ubc.ca
  104.  
  105. Gordon Wong, gordonw@unixg.ubc.ca
  106.  
  107.